package org.example.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.domain.po.ErpAccount;
import org.example.domain.po.ErpDepot;
import org.example.domain.po.ErpSupplier;
import org.example.service.ErpDepotService;
import org.example.mapper.ErpDepotMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 24059
* @description 针对表【erp_depot(仓库表)】的数据库操作Service实现
* @createDate 2024-11-04 16:47:48
*/
@Service
public class ErpDepotServiceImpl extends ServiceImpl<ErpDepotMapper, ErpDepot>
    implements ErpDepotService{
    public List<ErpDepot> selectByExample(){
        return this.baseMapper.selectByExample();
    }

    //分页条件查询
    @Override
    public Page<ErpDepot> findByPage(Page<ErpDepot> page, String depName, String remark, Long tenantId) {
        return baseMapper.findByPage(page, depName, remark, tenantId);
    }

    @Override
    public boolean modifyTheState(List<Integer> ids, String status) {
        if (status.equals("0")){
            return lambdaUpdate().set(ErpDepot::getEnabled, false).in(ErpDepot::getId, ids).update();
        }else {
            return lambdaUpdate().set(ErpDepot::getEnabled, true).in(ErpDepot::getId, ids).update();
        }
    }

    @Override
    public boolean SetDefault(Integer id) {
        String isDefault = baseMapper.findIsDefault();
        if (isDefault != null && isDefault.equals(String.valueOf(id))){
            return true;
        }
        if (isDefault!=null){
            lambdaUpdate().set(ErpDepot::getIsDefault, false).in(ErpDepot::getId, isDefault).update();
        }
        return lambdaUpdate().set(ErpDepot::getIsDefault, true).in(ErpDepot::getId, id).update();
    }
    
    @Override
    public List<ErpDepot> findDepotByTenantId(Long tenantId) {
        return lambdaQuery().eq(ErpDepot::getTenantId, tenantId).list();
    }
}




